// BrowseFileEdit.cpp : implementation file
//


#include "stdafx.h"
#include "resource.h"
#include "BrowseFileEdit.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CBrowseFileEdit::CBrowseFileEdit()
{
	m_bOpenFileDialog = TRUE;
}

BEGIN_MESSAGE_MAP(CBrowseFileEdit, CBCGPEdit)
END_MESSAGE_MAP()

void CBrowseFileEdit::OnBrowse()
{
	ASSERT_VALID (this);
	ASSERT (GetSafeHwnd () != NULL);
	if (m_Mode == BrowseMode_File)
	{
		CString strFile;
		GetWindowText (strFile);
		CFileDialog dlg (m_bOpenFileDialog? TRUE:FALSE, m_strDefFileExt, strFile, 
			OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN, 
			m_strFileFilter, NULL);
		if (dlg.DoModal () == IDOK &&
			strFile != dlg.GetPathName ())
		{
			SetWindowText (dlg.GetPathName ());
			SetModify (TRUE);
			OnAfterUpdate ();
		}

		if (GetParent () != NULL)
		{
			GetParent ()->RedrawWindow (NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN);
		}
	}
	SetFocus ();
}

void CBrowseFileEdit::EnableFileBrowseButton (BOOL bOpenFileDialog, LPCTSTR lpszDefExt/* = NULL*/, LPCTSTR lpszFilter/* = NULL*/)
{
	ASSERT_VALID (this);
	ASSERT (GetSafeHwnd () != NULL);
	m_Mode = BrowseMode_File;
	m_bOpenFileDialog = bOpenFileDialog;
	m_strDefFileExt = lpszDefExt == NULL ? _T("") : lpszDefExt;
	m_strFileFilter = lpszFilter == NULL ? _T("") : lpszFilter;
	SetIntenalImage ();
	OnChangeLayout ();
}
